package com.ag.wzp.action;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.apache.struts2.interceptor.SessionAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.ag.bean.TbEventmackup;
import com.ag.bean.TbMackupAnnex;
import com.ag.bean.TbUser;
import com.ag.common.BaseAction;
import com.ag.common.IPermissionService;
import com.ag.wzp.service.impl.MackupServiceImpl;
/**
 * @author 温镇澎
 * 
 */
@Scope("prototype")
@Controller("eventMackupAction")
public class EventMackupAction extends BaseAction implements SessionAware{
	private static final long serialVersionUID = 1L;
	private static final Logger logger = Logger.getLogger(EventMackupAction.class);
	/**
	 * 调用权限服务逻辑组件
	 */
	@Resource(name = "PermissionServiceImpl")
	private IPermissionService pms;
	/**
	 * 提供Map<String, Object>类型的Session变量，用来保存Struts2注入的Session上下文
	 */
	private Map<String, Object> sessionMap;
	@Override
	public void setSession(Map<String, Object> session) {
		this.sessionMap = session;
		
	}
	@Resource(name = "mackupServiceImpl")
	private MackupServiceImpl mackupServiceImpl;
	private List<TbEventmackup> mackups;
	private List<TbMackupAnnex> mackupAnnexs;
	private TbEventmackup mackup;
	private String EId;
	private String annexAddr;
	private String annexName;
	
	public void save(){
		mackup.setTbUser(pms.getCurrentUser(sessionMap));
		Boolean  b = this.mackupServiceImpl.save(mackup,annexAddr,annexName);
		this.outJsonString(b.toString());
	}
	
	public String findByEId(){
		mackups = this.mackupServiceImpl.findByEId(EId);
		for (TbEventmackup mackup : mackups){
			logger.info(mackup.getEmId());
			logger.info(mackup.getEmContext());
			for(TbMackupAnnex annex : mackup.getTbMackupAnnexes()){
				logger.info(annex.getMaAddress());
			}
		}
		return "findMackupByEId";
	}
	
	public String findMackupAnnexByEId(){
		mackupAnnexs = this.mackupServiceImpl.findAnnexByEId(EId);
		return "findMackupAnnexByEId";
	}
	public List<TbEventmackup> getMackups() {
		return mackups;
	}

	public void setMackups(List<TbEventmackup> mackups) {
		this.mackups = mackups;
	}

	public TbEventmackup getMackup() {
		return mackup;
	}

	public void setMackup(TbEventmackup mackup) {
		this.mackup = mackup;
	}

	public String getEId() {
		return EId;
	}

	public void setEId(String eId) {
		EId = eId;
	}

	public String getAnnexAddr() {
		return annexAddr;
	}

	public void setAnnexAddr(String annexAddr) {
		this.annexAddr = annexAddr;
	}

	public String getAnnexName() {
		return annexName;
	}

	public void setAnnexName(String annexName) {
		this.annexName = annexName;
	}
	 
	public List<TbMackupAnnex> getMackupAnnexs() {
		return mackupAnnexs;
	}

	public void setMackupAnnexs(List<TbMackupAnnex> mackupAnnexs) {
		this.mackupAnnexs = mackupAnnexs;
	}

}
